<div class="easyui-panel" id='pageSummary' title="统计信息" style="padding:10px; width:700px;">
    <table>
        <tr><td>会员可用总金额：<strong class="green">0.00</strong></td><td>会员总不可用余额：<strong class="red">0.00</strong></td></tr>
        <tr><td>System可用余额：<strong class="green">0.00</strong></td><td>购买坐席提成金额：<strong class="green">0.00</strong></td></tr>
    </table>
</div>
<script>
    $.post('?m=Api/FinanceAccount&action=read_summary',function(data){
        var $strongs=$('#pageSummary').find('strong');
        $strongs.eq(0).text(data.all);
        $strongs.eq(1).text(data.frozenblance);
        $strongs.eq(2).text(data.system);
        $strongs.eq(3).text(data.commission);
    },'json');
    </script>
<table id="dg" title="账户管理" class="easyui-datagrid" style="width:700px;height:250px" url="?m=Api/FinanceAccount"  toolbar="#toolbar" pagination="true"  rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
        <tr>
            <th field="UserName" width="50">用户名</th>
            <th field="Blance" width="50">可用余额</th>
            <th field="CreatedTime" width="50">开户时间</th>
            <th field="State" width="50" data-options="formatter:function(v,r,i){return getStateStr(r.ID,v);}">状态</th>
        </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">新增</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">编辑</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyItem()">删除</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyItem()">查看交易日志</a>
</div>
    
<div id="dlg" class="easyui-dialog" style="width:640px;height:500px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
    <div class="ftitle">编辑文章</div>
    <form id="fm" method="post">
        <div class="fitem">
            <label>标题：</label>
            <input name="title" class="easyui-validatebox" size='60' required="true" />
        </div>
        <div class="fitem">
            <label>分类：</label>
            <input class="easyui-combobox" name="catalog"  data-options="valueField:'id',textField:'name',url:'?m=Api/Catalog&tag=Article'">
        </div>
        <div class="fitem">
            <label>内容：</label>
            <textarea name="content" class="editor" rows="6"></textarea>
        </div>
        <input type='hidden' name='id' />
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" id="btnSave" onclick="saveItem()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
    <script type="text/javascript">
        var apiurl='?module=Api/FinanceAccount';
        function newItem(){
            $('#dlg').dialog('open').dialog('setTitle','新增');
            $('#fm').form('clear');
            setEditor();
        }
        function editItem(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('setTitle','编辑');
                //$('#fm').form('load',row);
                $('#fm').form('load',apiurl+'&action=read_one&id='+row.ID);
                setEditor();
            }
        }
        function saveItem(){
            $('#fm').form('submit',{
                url: apiurl+'&action=save',
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }
        function destroyItem(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('操作确认','您确定要删除此记录吗?',function(r){
                    if (r){
                        $.post(apiurl+'&action=remove',{id:row.ID},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        /**
         * 获取状态的值
         * @param {type} id
         * @param {type} v
         * @returns {String}
         * @since 1.0 2014-3-22 by sutroon
         */
        function getStateStr(id,v){
            return v==1?'<a href="javascript:void(0)" onclick="setItemState('+id+',0);">正常</a>':'<a href="javascript:void(0)" onclick="setItemState('+id+',1);">关闭<a>'
        }
        /**
         * 更新记录的状态
         * @param {type} id
         * @param {type} v
         * @returns {undefined}
         * @since 1.0 2014-3-22 by sutroon
         */
        function setItemState(id,v){
            alert(id);
            $.post(apiurl+'&action=set_state',{id:id,state:v},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
        }
        
    </script>